package com.qf.chinatelcom.smsatragety.mq.listener;

import com.qf.chinatelcom.smsatragety.evens.BlackListChangeEvent;
import com.qf.chinatelcom.smsatragety.evens.DirtyChangeEvent;
import com.qf.chinatelcom.smsatragety.evens.FilterChangeEvent;
import com.qf.chinatelcom.smsatragety.evens.LimitChangeEvent;
import com.qianfeng.smsplatform.common.constants.RabbitMqConsants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class LocalCacheChangeListener {

    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    /**
     * 发送事件
     * @param msg
     */
    //与input里边的消息对应起来
    @StreamListener(RabbitMqConsants.TOPIC_STRATEGYEXECFILTERS_UPDATE)
    public void onMessage(String msg) {
        context.publishEvent(new FilterChangeEvent());
    }

    @StreamListener(RabbitMqConsants.TOPIC_BLACKNUM_UPDATE)
    public void blackMessage(String msg){
        context.publishEvent(new BlackListChangeEvent());
    }

    @StreamListener(RabbitMqConsants.TOPIC_DIRTYWORDS_UPDATE)
    public void dirtyMessage(String msg){
        context.publishEvent(new DirtyChangeEvent());
    }

    @StreamListener(RabbitMqConsants.TOPIC_LIMIT_UPDATE)
    public void limitMessage(String msg){
        context.publishEvent(new LimitChangeEvent());
    }

}
